n, k = map(int, input().split())
work_time = list(map(int, input().split()))
stack, count = 0, 0

for i in range(len(work_time)):
    lowest = i
    for j in range(i + 1, len(work_time)):
        if work_time[j] < work_time[lowest]:
            lowest = j
            work_time[i], work_time[lowest] = work_time[lowest], work_time[i]

for i, num in enumerate(work_time):
    if num < n:
        if stack + num < n:
            stack += num
            count = i + 1
    else:
        break

print(count)
